//
//  CourseCollectionViewCell.m
//  Arts1
//
//  Created by lanou on 15/8/29.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "CourseCollectionViewCell.h"
#import "AllHeader.h"
#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h>
#import "UIImage+ImageBlur.h"
#import <UIImageView+WebCache.h>

@implementation CourseCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //  背景图片
        _mainImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, (SCREEN_WIDTH - 50)/4, (SCREEN_WIDTH - 50)/4)];
        _mainImageView.backgroundColor = kRandomColor;
        _mainImageView.layer.cornerRadius = 5;
        [_mainImageView setContentMode:(UIViewContentModeScaleAspectFill)];
        _mainImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_mainImageView];
        
        //  英文名称
        _englishName = [[UILabel alloc] initWithFrame:CGRectMake(5, _mainImageView.height - 38, _mainImageView.width - 10, 20)];
        _englishName.font = [UIFont fontWithName:@"AvenirNext-Bold" size:11];
        _englishName.textColor = [UIColor whiteColor];
        [_mainImageView addSubview:_englishName];
        
        // 中文名称
        _chinaName = [[UILabel alloc] initWithFrame:CGRectMake(5, _mainImageView.height - 20, _mainImageView.width - 10, 14)];
        _chinaName.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        _chinaName.textColor = [UIColor whiteColor];
        [_mainImageView addSubview:_chinaName];
        
    }
    return self;
}

- (void)setCate:(CourseCateModel *)cate{
    _cate = cate;
    
    if (_cate.backImg) {
        /**
         *  UIImageView+WebCache中的下面这个方法，可以对image进行操作
         *
         *  @param image     赋值给imageView的image
         *  @param error     发生错误的时候，错误原因
         *  @param cacheType 缓存类型
         *  @param imageURL  图片的来源
         *
         *  @return 已经赋过image值的imageView
         */
        [_mainImageView sd_setImageWithURL:[NSURL URLWithString:_cate.backImg] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            UIImage *bImage = [image boxblurImageWithBlur:0.75];
            _mainImageView.image = bImage;
        }];
    } else {
        UIImage *mImage = [UIImage imageNamed:@"coursePlaceHolder"];
        _mainImageView.image = [mImage boxblurImageWithBlur:0.35];
    }


    _chinaName.text = _cate.catName;
    _englishName.text = _cate.foreignName;

}

@end

